Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TOML parse failure when number token hits buffer edge #356

Merged
merged 2 commits into from
Nov 22, 2022

Conversation

yawkat
Copy link
Member

@yawkat yawkat commented Nov 22, 2022

When a number token is exactly at the end of the lexer text buffer, the parser would advance the lexer, triggering a buffer refill, before the number is parsed from the buffer. This patch moves the advance operation to come after parsing, which resolves the issue.

Kudos to @wbprime for finding this and reporting it as micronaut-projects/micronaut-toml#93 . Not even the fuzzer managed to hit this – maybe because it does not fail fast, and just returns the wrong output (NumberInput does no input checking)?

When a number token is exactly at the end of the lexer text buffer, the parser would advance the lexer, triggering a buffer refill, before the number is parsed from the buffer. This patch moves the advance operation to come after parsing, which resolves the issue.

Kudos to @wbprime for finding this and reporting it as micronaut-projects/micronaut-toml#93 . Not even the fuzzer managed to hit this – maybe because it does not fail fast, and just returns the wrong output (NumberInput does no input checking)?
@yawkat yawkat requested a review from cowtowncoder November 22, 2022 17:01
@yawkat
Copy link
Member Author

yawkat commented Nov 22, 2022

hm outstanding test failures...

yawkat added a commit to micronaut-projects/micronaut-toml that referenced this pull request Nov 22, 2022
When a number token is exactly at the end of the lexer text buffer, the parser would advance the lexer, triggering a buffer refill, before the number is parsed from the buffer. This patch moves the advance operation to come after parsing, which resolves the issue.

Also tracked as FasterXML/jackson-dataformats-text#356

Fixes #93
@yawkat
Copy link
Member Author

yawkat commented Nov 22, 2022

i think the fuzz tests just fail because of illegal tokens now, but as long as there's a failure, this seems fine

@cowtowncoder
Copy link
Member

@yawkat Correct, many/most methods in NumberInput expect caller to pass valid Strings (since that's what original JSON parser does before calls anyway). This is good for performance but can in fact hide errors like buffer boundary ones.
Fuzzer also has the challenge that it can find buffer boundary if it results ArrayIndexOutOfBoundsException but not if it just produces invalid output (like you suggested).

@cowtowncoder cowtowncoder merged commit 0ba64a6 into 2.14 Nov 22, 2022
@cowtowncoder cowtowncoder deleted the chunk-edge branch November 22, 2022 17:48
cowtowncoder added a commit that referenced this pull request Nov 22, 2022
yawkat added a commit to micronaut-projects/micronaut-toml that referenced this pull request Nov 23, 2022
When a number token is exactly at the end of the lexer text buffer, the parser would advance the lexer, triggering a buffer refill, before the number is parsed from the buffer. This patch moves the advance operation to come after parsing, which resolves the issue.

Also tracked as FasterXML/jackson-dataformats-text#356

Fixes #93

Co-authored-by: Tim Yates <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants